package cn.tedu.review;

import java.io.*;

/*测试字符流的读取*/
public class TestIn2 {
    public static void main(String[] args) {
        //method1();//普通字符输入流
        method2();//高效字符输入流
    }

    private static void method2() {
        Reader in=null;
        try {
            in=new BufferedReader(new FileReader(new File("D:\\ready\\1.txt")));
            in=new BufferedReader(new FileReader("D:\\ready\\1.txt"));
            int b;
            while ((b=in.read())!=-1){
                System.out.println(b);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    private static void method1() {
        Reader in=null;
        try {
            in=new FileReader(new File("D:\\ready\\1.txt"));
            in=new FileReader("D:\\ready\\1.txt");

            //会产生跳着读的效果,会遗漏数据
            while (in.read()!=-1){
                System.out.println(in.read());
            }

        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
